export const arrToTree = <T extends Record<string, any>, K extends keyof T>(arr: Array<T>, key: K, fKey: K, startFKey: T[K]) => {
  if(!Array.isArray(arr)) {throw new Error('数组呢?玩呢!!')}
  function _updateChildren(node: T & {children?: Array<T>}) {
    const children = arr.filter(item => item[fKey] === node[key])
    if(children.length > 0) {
      node.children = children.map(item => _updateChildren(Object.assign({}, item)))
    }
    return node
  }
  return arr.filter(item => item[fKey] === startFKey).map(item => _updateChildren(Object.assign({}, item)))
}


